import cv2

# author: 徐锐
# 直线拟合


class LSD:
    @staticmethod
    def LSD(image):
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        image = cv2.equalizeHist(image)
        lsd = cv2.createLineSegmentDetector(0)
        dlines = lsd.detect(image)
        for dline in dlines[0]:
            x0 = int(round(dline[0][0]))
            y0 = int(round(dline[0][1]))
            x1 = int(round(dline[0][2]))
            y1 = int(round(dline[0][3]))
            cv2.line(image, (x0, y0), (x1, y1), (0, 0, 255), 1, cv2.LINE_AA)
        return image
